package com.xiaren.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import com.xiaren.comm.DBHelp;
import com.xiaren.comm.Dao;

public class RunBlackName {
	
	
	public static void main(String[] args) throws Exception  {
		killconn();
	}
	
	static void killconn() throws Exception {
		Dao dao = new Dao();
		DBHelp db = new DBHelp();
		Connection conn = db.getConnection(null,
				"jdbc:oracle:thin:@localhost:1521:ORCL", "SYSTEM", "XIAREN");
		String findsql = "SELECT t.sid,t.serial# FROM V$session t WHERE t.username = 'SCOTT' AND STATUS = 'INACTIVE'";
		List<Object[]> listobj = dao.query(conn, findsql);
		for (Object[] objects : listobj) {
			int sid = Integer.parseInt(objects[0].toString());
			int serial = Integer.parseInt(objects[1].toString());
			String sql = "alter system kill session '" + sid + "," + serial + "'";
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.executeUpdate();
		}
		DBHelp.close(null, null, null, conn);
	}
}
